import axios from 'axios'
import router from '../router/index'
let http = axios.create({
    timeout:10000,
    baseURL:'/api'
})
// process.env.NODE_ENV==='development'?
//     http.defaults.baseURL = process.env.VUE_APP_BASE_URL:
//     http.defaults.baseURL = process.env.VUE_APP_BASE_URL
http.interceptors.request.use(req=>{
    let token = sessionStorage.getItem('token')
    token && (req.headers['Authorization'] = `Bearer ${token}`)
    return req
},error=>Promise.reject(error))
http.interceptors.response.use(resp=>{
    resp.data.token && sessionStorage.setItem('token',resp.data.token)
    return resp
},error=>{
    // let _resp = error.response
    // switch (_resp.status) {
    //     case 401 :
    //         sessionStorage.clear()
    //         alert('身份已过期,请重新登录')
    //         return router.push('/login')
    // }
    return Promise.reject(error.response.data)
})

export default http